package com.wanmait.recycle.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recycle.mapper.AdminMapper;
import com.wanmait.recycle.pojo.Admin;
import com.wanmait.recycle.service.AdminService;
import com.wanmait.recycle.service.ConfigService;
import com.wanmait.recycle.util.PageContext;
import com.wanmait.recycle.util.Pager;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {

	
	@Resource
	private AdminMapper adminMapper;
	@Resource
	private ConfigService configService;
	
	@Override
	public void insert(Admin object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(Admin object) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(Integer id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(String ids) {
		// TODO Auto-generated method stub

	}

	@Override
	public Admin findById(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	//用于adminList ad 02.25
	@Override
	public List<Admin> findAll() {
		// TODO Auto-generated method stub
		return adminMapper.findAll() ;
	}

	@Override
	public int getDataCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Admin> findAll(Pager pager) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Admin> findAll(Admin object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getDataCount(Admin object) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Admin> findAll(Pager pager, Admin object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Admin selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return adminMapper.selectByPrimaryKey(id);
	}

	//根据id更改密码 ad 02.25
	@Override
	public void updateById(Integer id,String pass) {
		// TODO Auto-generated method stub
		adminMapper.updateById(id,pass);
	}
	/*根据用户名查找某个用户 zq 02.25*/
	@Override
	public Admin findAdminByNameAndPassword(String name,String password) {
		
		return adminMapper.findAdminByNameAndPassword(name, password);
	}


	@Override
	public void insertAdmin(Admin object) {
		// TODO Auto-generated method stub
		 adminMapper.insert(object);
	}

	@Override
	public void deleteAdmin(Integer id) {
		// TODO Auto-generated method stub
		adminMapper.deleteByPrimaryKey(id);
	}
	
	@Override
	public void deleteAdmins(String ids)
	{
		ids = ids.substring(0, ids.length()-1);
		String[] nn =ids.split(",");
		
		adminMapper.deleteByIds(nn);
	}

	@Override
	public void reAddAdmin(Integer id) {
		// TODO Auto-generated method stub
		adminMapper.reAdd(id);
	}

	@Override
	public void up(Integer id) {
		// TODO Auto-generated method stub
		adminMapper.up(id);
	}

	@Override
	public void down(Integer id) {
		// TODO Auto-generated method stub
		adminMapper.down(id);
		}

	@Override
	public int selectSuperCount() {
		// 
		return adminMapper.selectSuperCount();
	}

	@Override
	public PageInfo<Admin> findAllByPage() {
		Map<String, Map<String,String>> config = configService.findAllConfig();
		PageHelper.startPage(PageContext.getPageNum(), Integer.parseInt(config.get("管理员分页").get("managerPage")));
		List<Admin> admins = adminMapper.findAllByPage();
		PageInfo<Admin> pageInfo = new PageInfo<Admin>(admins,7);
		return pageInfo;
	}

	@Override
	public boolean isAdminByExample(Admin admin) {
		boolean f = false;
		if(adminMapper.isAdminByExample(admin)==null) {
			f = false;
		}else {
			f = true;
		}
		
		return  f;
	}
}
